package com.work.app.config;


import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;


@Slf4j
@Configuration
//@EnableAspectJAutoProxy
public class WebMvcConfig extends WebMvcConfigurationSupport {


    @Value("${web.upload-path}")
    private String uploadPath;//配置文件中配置的路径
    @Value("${web.static-path}")
    private String staticPath;
    /**
     * 设置静态资源映射
     * @param registry 资源处理程序注册表
     */
    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        log.info("开始进行静态资源映射...");
        registry.addResourceHandler("/**") //访问url头
                .addResourceLocations("classpath:/static/"); //开启的静态资源路径

        registry.addResourceHandler(staticPath+"**") //访问url头
                .addResourceLocations("file:/"+uploadPath); //开启本地文件资源路径
        super.addResourceHandlers(registry);
        //registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
    }

    //    /**
//     * 添加 自定义的Jwt过滤器
//     * @param registry
//     */
//    @Override
//    protected void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(new JwtRoleInterceptor())
//                .excludePathPatterns("/users/login")  //放行登录
//                .excludePathPatterns("/users/logout")//放行登出
//                .excludePathPatterns("/users/checkToken")//校验token
//                .excludePathPatterns("/users/check-username") //放行检测账号
//                .excludePathPatterns("/users/create") //放行注册
//                .excludePathPatterns("/users/getTastes") //放行爱好获取
//                //.excludePathPatterns(uploadPath+"/*.*")
//                .addPathPatterns("/**");
//    }
//    @Bean
//    public JwtRoleInterceptor authenticationInterceptor(){
//        return new JwtRoleInterceptor();
//    }
}

